﻿#include<iostream>
using namespace std;

const int N = 500007;
int arr[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	char c;
	while (T--)
	{
		cin >> c;
		int pos = 0;
		while (c != ']')
		{
			cin >> arr[pos++] >> c;
		}
		int x, y;
		cin >> x >> y;
		cout << '[';
		int p = 0;
		for (int i = 0; i < x; i++)
		{
			cout << '[';
			for (int j = 0; j < y; j++)
			{
				if (j == y - 1)cout << arr[p];
				else cout << arr[p] << ", ";
				p++;
			}
			if (i == x - 1)cout << ']';
			else cout << "], ";
		}
		cout << ']' << endl;
	}
	return 0;
}